package vn.cuhanh.customview;

import vn.cuhanh.utils.HelperFunc;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;

public class SingleShotImageView extends ImageView {

	public SingleShotImageView(Context context) {
		super(context);
	}

	public SingleShotImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public SingleShotImageView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	protected void onDetachedFromWindow() {
		Drawable dw = getDrawable();

		try {
			if (dw != null) {
				Bitmap bitmap = ((BitmapDrawable) dw).getBitmap();
				if (bitmap != null && bitmap.isRecycled()) {
					bitmap.recycle();
					bitmap = null;
				}
				// System.gc();
			}
			setImageDrawable(null);
			setBackgroundDrawable(null);
		} catch (Exception e) {
			HelperFunc.readStackTrace(e);
		}

	}
	
	
}
